﻿using System;

namespace Syno.Core.Output.DataDisplay
{
    public class DataHolder : IDataHolder
    {
        private readonly string _id;
        private readonly IDataLoader _dataLoader;
        private readonly IDataDisplay _dataDisplay;
        private INVelocityTemplates _templates;


        public DataHolder(string id, IDataLoader dataLoader, IDataDisplay dataDisplay)
        {
            _id = id;
            _dataLoader = dataLoader;
            _dataDisplay = dataDisplay;
        }

        public IDataLoader DataLoader
        {
            get { return _dataLoader; }
        }

        public IDataDisplay DataDisplay
        {
            get { return _dataDisplay; }
        }

        public string Id
        {
            get { return _id; }
        }

        public string Data
        {
            get {
                _dataLoader.SetTemplater(_templates);
                var data = _dataLoader.ReadData();
                return _dataDisplay.Display(data);
            }
        }

        public void SetTemplater(INVelocityTemplates dataHolders)
        {
            _templates = dataHolders;
        }
    }
}